package pro.softzhang.algo.lc100;

import pro.softzhang.algo.flag.knowledge.KBinarySearch;

/**
 * 162. 寻找峰值
 * https://leetcode.cn/problems/find-peak-element
 */
public class LC162_FindPeakElement {
    public static void main(String[] args) {
        int[] nums = {1, 2, 3};
        System.out.println(new Solution().findPeakElement(nums));
    }

    /**
     * 
     */
    @KBinarySearch
    static
    class Solution {
        public int findPeakElement(int[] nums) {
            int left = -1, right = nums.length - 1;
            while (left + 1< right) {
                int mid = left + (right - left) / 2;
                if (nums[mid] > nums[mid + 1])
                    right = mid;
                else
                    left = mid;
            }
            return right;
        }
    }
}
